# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_cor-43things_session_id2'
  @application_title = "app_title".t
  
  before_filter :set_charset  
  before_filter :set_locale
  
  def set_charset      
    logger.debug "======in application controller set_charset"
    content_type = headers["Content-Type"] || "text/html"       
    if /^text\//.match(content_type)        
      headers["Content-Type"] = "#{content_type}; charset=utf-8"       
    end  
  end
    
  def set_locale   
    logger.debug "======in application controller set_locale"
    default_locale = 'zh-CN'  
    request_language = request.env['HTTP_ACCEPT_LANGUAGE']  
    request_language = request_language.nil? ? nil : request_language[/[^,;]+/]  
    @locale = params[:locale] || session[:locale] || request_language || default_locale  
    session[:locale] = @locale  

    begin    
      Locale.set @locale  
    rescue    
      Locale.set default_locale  
    end
    true
  end
end
